import { defineStore } from "pinia";
import img from "../utils";
import { getFollow, getUnFollow, getuserinfo } from "../http";
console.log("this", this);
export const useCounterStore = defineStore("counter", {
  state: () => ({
    loginer: JSON.parse(localStorage.getItem("info")) || "",
    info: "",
    sendMsg: "",
    socketOB: null, //
    socketChatOB: null, //聊天的实例

    joinPrivateSD: null,
    takePrivateSD: [],
    loginSD: null,
    joinRoom: null,
    welcomeSD: null,
    AllonlineUsrs: null,
    adminUsrs: null,
    nobleUsrs: null,
    leftOnLineUsr: null,
    rightTrueUsr: null,
    isOptionSucess: false,
    //                   被邀请方点击同意or拒绝后的回调信息
    beInviteCallbackInfo: null,
    // 是否同意pk
    isAgreePK: 2,
    OtherSideAgree: false,
    OtherSideInfo: null,
    isjoin: 0,
    // 是否操作
    isCaption: false,
    changeSelectEvtValVedio: "",
    changeSelectEvtValAudio: "",
    // 测试直播
    startLive: false,
    // 是否已经获取到用户信息
    isTakeTeamInfo: false,
    //  B做出回复
    replySuccess: false,
    // 踢出自己或者别人
    isTickSuccess: false,
    // 邀请状态
    inviteSucess: false,
    // 是否已发送
    sendSucess: false,
    // 创建团队的信息
    createTeamInfo: null,
    // 团队的id
    teamId: "",
    // 被邀请人的列表
    inviteList: [],
    // 用来判断是否进入团队
    isIntoTeam: false,
    // set设置功能这一块
    setList: {},
    // adminlist:[],
    // tickoutlist:[],
    // jinyanlist:[],
    // laheilist:[],

    isLine: false,
    // 打开set窗口
    isSetDialog: false,
    mapperFoot: {
      foot1: false,
      foot2: false,
      foot3: false,
      foot4: false,
      foot5: false,
    },
    // 消息
    sendInfo: null,
    rightMsgList: [],
    minMsgList: [],
    // 贡献榜
    isContrib: false,
    contribuInfo: null,
    //
    isLivePro: false,
    // pk 对话框
    isPkDialog: false,
    liveProInfo: null,
    isLivePkDialog: false,
    isGiftDialog: false,
    // 私聊对话框
    isPrivateChat: false,
    // 开麦
    openOffMike: false,
    //是否禁言
    isForbiTalk: false,
    // 拒绝同意
    isRejuect: false,
    isAgent: false,
    goAsk: false,
    mikeAskInf: [],
    mikeManageInf: [],
    inpValSend: "",
    // `````````````````````````````
    // 邀请是否成功发送
    sendInviteSucess: false,
    // 被邀请方是否监听到邀请方的邀请
    isWatchOthrInvite: false,
    // 邀请人的信息
    inviteMsg: null,
    mapperLevel: {
      // 财富
      英勇游侠: new URL("../assets/ic_cf1.png", import.meta.url).href,
      圣殿骑士: new URL("../assets/ic_cf2.png", import.meta.url).href,
      桀骜领主: new URL("../assets/ic_cf3.png", import.meta.url).href,
      荣耀伯爵: new URL("../assets/ic_cf4.png", import.meta.url).href,
      尊贵公爵: new URL("../assets/ic_cf5.png", import.meta.url).href,
      傲世君王: new URL("../assets/ic_cf6.png", import.meta.url).href,

      // 魅力
      宠宠新人: new URL("../assets/ic_ml1.png", import.meta.url).href,
      C位学员: new URL("../assets/ic_ml2.png", import.meta.url).href,
      当红小生: new URL("../assets/ic_ml3.png", import.meta.url).href,
      人气明星: new URL("../assets/ic_ml4.png", import.meta.url).href,
      世界大咖: new URL("../assets/ic_ml5.png", import.meta.url).href,
      国民偶像: new URL("../assets/ic_ml6.png", import.meta.url).href,
      璀璨巨星: new URL("../assets/ic_ml7.png", import.meta.url).href,
      传奇: new URL("../assets/ic_ml8.png", import.meta.url).href,
    },
    mappeFollow: {
      0: async function (data) {
        return await getFollow(data);
      },
      1: async function (data) {
        return await getUnFollow(data);
      },
    },
  }),
  getters: {},
  actions: {
    async handleFollow() {
      if (!this.liveProInfo) {
        return;
      }
      let data = {
        followuid: this.liveProInfo?.obj1?.id,
        jwt: this.loginer?.jwt,
      };
      let res = await this.mappeFollow[this.liveProInfo?.obj2?.isfollow](data);
      if (res?.errcode === 0 || res?.data?.errcode === 0) {
        // 重新刷新数据
        let reInfo = await getuserinfo({
          userid: this.liveProInfo?.obj1?.id,
          jwt: this.loginer.jwt,
        });
        this.liveProInfo = {
          obj2: { ...this.liveProInfo.obj2, isfollow: reInfo?.data?.isfollow },
          obj1: { ...this.liveProInfo.obj1 },
        };
      }
    },
  },
});
export default useCounterStore;
